var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AudioManager"),
    s = e("PureHelper"),
    l = e("Game"),
    c = e("RoleSoldierInfo"),
    d = e("Toast"),
    h = e("node_team"),
    _ = e("role_node"),
    u = cc._decorator,
    p = u.ccclass,
    m = u.property,
    f = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.monster_ske = null),
                (t.monster_type = l.MonsterType.red),
                (t.monster_hp_mask = null),
                (t.monster_level = null),
                (t.monster_hp_label = null),
                (t.monster_name_label = null),
                (t.coin_system = null),
                (t.monster_common_skill = null),
                (t.monster_skill_one = null),
                (t.monster_skill_two = null),
                (t.monster_info = null),
                (t.max_hp_num = 0),
                (t.now_hp_num = 0),
                (t.attack_num = 0),
                (t.monster_id = 0),
                (t.attack_target = null),
                (t.moster_attack = !1),
                (t.ack_range = 0),
                (t.monster_move = !1),
                (t.start_pos = null),
                (t.is_die = !1),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.initView = function () {
                for (var e = this, t = 0, o = this.node.getComponentsInChildren(cc.BoxCollider); t < o.length; t++) {
                    var n = o[t];
                    1 == n.tag &&
                        ((this.monster_common_skill = n),
                        (n.enabled = !1),
                        (this.ack_range = 1.5 * Math.abs(n.offset.x))),
                        2 == n.tag && ((this.monster_skill_one = n), (n.enabled = !1)),
                        3 == n.tag && ((this.monster_skill_two = n), (n.enabled = !1));
                }
                (this.start_pos = this.node.getPosition()),
                    this.node.getComponent(h.default).setTeamInfo(l.TeamInfo.rest_team),
                    this.monster_ske.setAnimation(0, "battle_idle", !0),
                    (this.monster_info = c.default.moster_info[this.monster_type - 1]);
                var a = i.GlobalParams.MonsterDisNum[this.monster_type - 1];
                (this.monster_level.string = "" + (a.num + 1)),
                    (this.monster_name_label.string = "" + this.monster_info.name),
                    (this.max_hp_num = this.monster_info.hp[a.num]),
                    (this.now_hp_num = this.max_hp_num),
                    (this.attack_num = this.monster_info.attack[a.num]),
                    (this.monster_hp_mask.width = 270),
                    (this.monster_hp_label.string = "" + this.now_hp_num),
                    (this.monster_id = 10 + this.monster_type),
                    (this.node.scaleX *= this.monster_type == l.MonsterType.red ? -1 : 1),
                    (this.monster_name_label.node.scaleX = this.monster_hp_label.node.scaleX = this.node.scaleX),
                    this.monster_ske.setCompleteListener(function (t, o) {
                        e.monsterSkinCompleteListener(t, o);
                    }),
                    (this.coin_system.node.active = !1);
            }),
            (t.prototype.mosnterMove = function (e) {
                var t = this;
                if (this.monster_move) {
                    "run" != this.monster_ske.animation && this.playAnimation("run", !0),
                        0 != e.x &&
                            ((this.node.scaleX = Math.abs(this.node.scaleX) * (e.x < 0 ? 1 : -1)),
                            (this.monster_name_label.node.scaleX = this.monster_hp_label.node.scaleX =
                                this.node.scaleX));
                    var o = this.node.getPosition().add(e.mul(30));
                    this.attack_target && cc.isValid(this.attack_target, !0)
                        ? cc
                              .tween(this.node)
                              .to(i.GlobalParams.GameUpdateTime, {position: cc.v3(o.x, o.y, 0)})
                              .call(function () {
                                  t.mosterAttackSkill();
                              })
                              .start()
                        : cc
                              .tween(this.node)
                              .to(i.GlobalParams.GameUpdateTime, {position: cc.v3(o.x, o.y, 0)})
                              .call(function () {
                                  Math.abs(s.default.Distance(t.node.getPosition(), t.start_pos)) < 50
                                      ? ((t.monster_move = !1),
                                        (t.node.scaleX = t.monster_type == l.MonsterType.red ? -1 : 1),
                                        (t.monster_name_label.node.scaleX = t.monster_hp_label.node.scaleX =
                                            t.node.scaleX),
                                        t.node.setPosition(t.start_pos),
                                        t.playAnimation("battle_idle", !0),
                                        (t.now_hp_num = t.max_hp_num),
                                        (t.monster_hp_mask.width = 270),
                                        (t.monster_hp_label.string = "" + t.now_hp_num))
                                      : t.mosnterMove(e);
                              })
                              .start();
                }
            }),
            (t.prototype.attackMonster = function (e, t, o) {
                (this.attack_target = o),
                    this.moster_attack || ((this.moster_attack = !0), this.mosterAttackSkill()),
                    (this.now_hp_num -= e),
                    this.emitEvent(a.default.SEND_SHOW_BE_HIT_INFO, {
                        attack: e,
                        my_team: 0,
                        end_pos: cc.v2(this.node.getPosition().x, this.node.getPosition().y + 80)
                    }),
                    (this.now_hp_num = this.now_hp_num < 0 ? 0 : this.now_hp_num),
                    (this.monster_hp_mask.width = (270 * this.now_hp_num) / this.max_hp_num),
                    (this.monster_hp_label.string = "" + this.now_hp_num),
                    this.now_hp_num <= 0 &&
                        !this.is_die &&
                        ((this.is_die = !0),
                        this.emitEvent(a.default.SEND_ROLE_BE_KILL_INFO, {
                            kill: t,
                            be_kill: this.monster_id,
                            team: l.TeamInfo.rest_team
                        }),
                        (this.coin_system.node.active = !0),
                        r.default.getInstance().playFx("bome_coin"),
                        this.coin_system.resetSystem(),
                        this.monster_type == l.MonsterType.red
                            ? (this.attack_target.getComponent(_.default).addRoleEffects(l.RoleEffectType.red_buff),
                              d.default.showNewToast(this.monster_info.name + "之力"))
                            : this.monster_type == l.MonsterType.bule
                            ? (this.attack_target.getComponent(_.default).addRoleEffects(l.RoleEffectType.blue_buff),
                              d.default.showNewToast(this.monster_info.name + "之力"))
                            : this.monster_type == l.MonsterType.big_dragon &&
                              (this.emitEvent(
                                  a.default.SEND_ROLE_ADD_BIG_DRAGON_BUFF,
                                  this.attack_target.getComponent(_.default).match_game_index
                              ),
                              d.default.showNewToast(this.monster_info.name + "之力")),
                        r.default.getInstance().playFx("monster_die"),
                        this.emitEvent(a.default.SEND_COCOS_ANALYTICS, {
                            name: "事件一",
                            info: "击杀野怪：" + this.monster_info.name
                        }),
                        this.playAnimation("death", !1));
            }),
            (t.prototype.mosterAttackSkill = function () {
                if (cc.isValid(this.attack_target, !0) && !this.is_die)
                    if (
                        Math.abs(s.default.Distance(this.node.getPosition(), this.attack_target.getPosition())) <
                        this.ack_range
                    )
                        Math.abs(this.attack_target.y - this.node.y) > 50
                            ? ((this.monster_move = !0),
                              this.mosnterMove(cc.v2(0, this.attack_target.y > this.node.y ? 1 : -1)))
                            : ((this.monster_move = !1),
                              (this.node.scaleX = this.node.x > this.attack_target.x ? 1 : -1),
                              (this.monster_name_label.node.scaleX = this.monster_hp_label.node.scaleX =
                                  this.node.scaleX),
                              this.monsterAttackInfo());
                    else {
                        this.monster_move = !0;
                        var e = cc
                            .v2(this.attack_target.x, this.attack_target.y)
                            .sub(this.node.getPosition())
                            .normalize();
                        this.mosnterMove(e);
                    }
                cc.isValid(this.attack_target, !0) ||
                    ((this.attack_target = null),
                    (this.monster_move = !1),
                    (e = cc.v2(this.start_pos.x, this.start_pos.y).sub(this.node.getPosition()).normalize()),
                    this.mosnterMove(e));
            }),
            (t.prototype.monsterAttackInfo = function () {
                var e = this,
                    t = this.monster_ske.setAnimation(0, "attack", !0);
                this.monster_ske.setTrackEventListener(t, function () {
                    e.monstrtCommonSkill(!1, "attack"), e.monstrtCommonSkill(!0, "attack");
                });
            }),
            (t.prototype.monsterSkinCompleteListener = function (e) {
                var t = e.animation ? e.animation.name : "";
                -1 != ["attack", "attack_skill1", "attack_skill2"].indexOf(t) &&
                    (this.monstrtCommonSkill(!1, t),
                    (this.monster_ske.timeScale = 1),
                    this.monster_ske.clearTracks(),
                    this.playAnimation("battle_idle", !0),
                    this.mosterAttackSkill()),
                    "death" == t &&
                        (i.GlobalParams.MonsterDisNum[this.monster_type - 1].num++,
                        (i.GlobalParams.MonsterDisNum[this.monster_type - 1].time = this.monster_info.revive_time),
                        (i.GlobalParams.MonsterDisNum[this.monster_type - 1].exist = !1),
                        this.node.destroy());
            }),
            (t.prototype.monstrtCommonSkill = function (e, t) {
                (this.monster_common_skill.enabled = e && "attack" == t),
                    this.monster_skill_one && (this.monster_skill_one.enabled = e && "attack_skill1" == t),
                    this.monster_skill_two && (this.monster_skill_two.enabled = e && "attack_skill2" == t);
            }),
            (t.prototype.playAnimation = function (e, t) {
                "death" != this.monster_ske.animation && this.monster_ske.setAnimation(0, e, t);
            }),
            (t.prototype.onCollisionEnter = function (e, t) {
                var o = e.node,
                    n = o.group;
                if (
                    (!cc.isValid(o, !0) ||
                        (1 != t.tag && 2 != t.tag && 3 != t.tag) ||
                        0 != e.tag ||
                        ("role" == n && o.getComponent(_.default).roleBeHit(this.attack_num, this.monster_id)),
                    "map" == n && 0 == t.tag)
                ) {
                    (this.attack_target = null), (this.monster_move = !0), (this.moster_attack = !1);
                    var a = cc.v2(this.start_pos.x, this.start_pos.y).sub(this.node.getPosition()).normalize();
                    this.mosnterMove(a);
                }
            }),
            __decorate([m(sp.Skeleton)], t.prototype, "monster_ske", void 0),
            __decorate(
                [m({type: cc.Enum(l.MonsterType), displayName: "野怪类型"})],
                t.prototype,
                "monster_type",
                void 0
            ),
            __decorate([m(cc.Node)], t.prototype, "monster_hp_mask", void 0),
            __decorate([m(cc.Label)], t.prototype, "monster_level", void 0),
            __decorate([m(cc.Label)], t.prototype, "monster_hp_label", void 0),
            __decorate([m(cc.Label)], t.prototype, "monster_name_label", void 0),
            __decorate([m(cc.ParticleSystem)], t.prototype, "coin_system", void 0),
            __decorate([p], t)
        );
    })(n.default);
o.default = f;
